package com.xinggq.user.service.config;

import com.xinggq.user.service.interceptor.UserContextInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC配置类
 * 配置拦截器、跨域等Web相关设置
 * 
 * @author xinggq
 * @since 2025/1/20
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final UserContextInterceptor userContextInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册用户上下文拦截器
        registry.addInterceptor(userContextInterceptor)
                .addPathPatterns("/**") // 拦截所有请求
                .excludePathPatterns(
                        "/actuator/**",                    // 排除健康检查等监控端点
                        "/swagger-ui/**",                  // 排除Swagger UI
                        "/v3/api-docs/**",                 // 排除API文档
                        "/error",                          // 排除错误页面
                        "/api/user/auth/**"                // 排除用户认证相关接口
                );
    }
}